#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <head/g_pch.h>
#include <support/mysql_helper.h>
#include <support/odbc_helper.h>

#include "logviewer.h"
#include "querywidget.h"
#include "entityeditor.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void startUp();
    bool initializeMySQL();
    bool initializeODBC();

    void prepareMenubar();
    void prepareQueryWidget(const QString &entry);

    QMap<QString,QString> fetchStatement(const QString &entry);

    void updateQueryMenu();
    void updateEditMenu();

    void showMessage(const QString &message);

signals:
    void appendLog(const QString &log);

protected:
    void processQueryMenu(QAction *action);

private slots:
    void on_actionLogViewer_triggered();

    void on_actionEntityEditor_triggered();

private:
    Ui::MainWindow *ui;

    QSqlDatabase mysql;
    QSqlDatabase odbc;

    QString menuTable;
    QString statementTable;
    QString selectEntry;

    LogViewer *logViewer;
    QueryWidget *queryWidget;
    EntityEditor *entityEditor;

    QMap<QString,QString> queryMenuCache;
};
#endif // MAINWINDOW_H
